<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>商家管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="resources/css/public.css" media="all"/>
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    商家ID： <input type="text" class="layui-input idVal" placeholder="请输入商家ID"/>
                </div>
                <div class="layui-input-inline" >
                    商家状态： <input type="text" class="layui-input statetVal" placeholder="请输入状态"/>
                </div>
                <div class="layui-input-inline">
                    商家账号： <input type="text" class="layui-input numVal" placeholder="请输入商家账号"/>
                </div>
                <div class="layui-input-inline" >
                    注册时间1： <input type="text" class="layui-input startVal" placeholder="请输入开始时间"/>
                 </div>
                <div class="layui-input-inline">
                    注册时间2： <input type="text" class="layui-input endVal" placeholder="请输入结束时间"/>
                </div>
                              <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>
        </form>
    </blockquote>
    <table id="mUserTable" lay-filter="mUserTable">
    </table>
    <!--操作-->
    <script type="text/html" id="statusTpl">
        <input type="checkbox" lay-skin="switch" name="status" id="status" lay-filter="status" value={{d.state}} lay-text="正常|锁定" {{ d.state == 1 ? "checked" : ""  }}  >
    </script>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script type="text/javascript" th:inline="none">
    layui.use(['form', 'layer', 'table', 'laytpl'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table;
        //用户列表
        var tableIns = table.render({
            elem: '#mUserTable',
            url: 'mUserSelectByPage.do',
            cellMinWidth: 95,
            page: true,
            height: "full-200",
            limits: [10, 15, 20, 25],
            limit: 10,
            id: "mUserTablezz",
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},
                {field: 'id', title: '商家ID', minWidth: 100, align: "center"},
                {field: 'm_phoneNum', title: '账号', minWidth: 100, align: "center"},
                {field: 'm_password', title: '密码', minWidth: 100, align: "center"},
                {field: 'm_name', title: '名称', minWidth: 100, align: "center"},
                {field: 'm_licenseNum', title: '营业执照编号', align: 'center'},
                {field: 'm_contactway', title: '联系方式', align: 'center'},
                {field: 'm_address', title: '详细地址', align: 'center'},
                {
                    field: 'regtime', title: '注册时间', align: 'center', minWidth: 90, templet: function (obj) {
                        return obj.regtime;
                    }
                },
                {field: 'balance', title: '账号余额', align: 'center'},
                {title: '状态', width: 260, field: 'state', fixed: "right", align: "center", templet: '#statusTpl'}
            ]]

        });

        //实现搜索功能
        $(".search_btn").click(function () {
            var id = $(".idVal").val();
            var m_phoneNum=$(".numVal").val();
            var state=$(".statetVal").val();
            var begin=$(".startVal").val();
            var end=$(".endlVal").val();
            table.reload('mUserTablezz', {
                 where: {
                     id:id,
                     m_phoneNum:m_phoneNum,
                     state:state,
                     begin:begin,
                     end:end
                 }
            });
        });

        form.on('switch(status)',function(data) {
                var checked=data.elem.checked;//当前是否选中状态
                var state=$('#status').val();
                console.log(checked);
                console.log(state);
            if (state==0)
            {
                if (checked=="true") {
                    var state = state + 1;
                    $.ajax({
                        url: "updateState.do",
                        data: {state: state, id: id},
                        type: "POST",
                        dataType: "json",
                        success: function (res) {
                            layer.msg("更改成功");
                        }
                    });
                }
            }else if (state==1) {
                if (checked =="false") {
                    var state = state - 1;
                    $.ajax({
                        url: "",
                        data: {state: state, id: id},
                        type: "POST",
                        dataType: "json",
                        success: function (res) {
                            layer.msg("更改成功");
                        }
                    });
                }
            }
        })

    });

</script>
</body>
</html>